//
//  MapManager.m
//  maosheng
//
//  Created by lxl on 2019/8/19.
//

#import "MapManager.h"

@implementation MapManager
+(id)shareInstance{
    static MapManager* dataCenter = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (dataCenter == nil)
        {
            [[BMKLocationAuth sharedInstance] checkPermisionWithKey:@"9evhhSk5Gzybuo3OQN3dIud38oprurd7" authDelegate:self];
            dataCenter = [[MapManager alloc] init];
        }
    });
    return dataCenter;
}
- (void)getCurrentLocation{
    BMKLocationManager  *locationManager = [[BMKLocationManager alloc] init];
    self.mapManager = locationManager;
    locationManager.delegate = self;
    locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.activityType = CLActivityTypeAutomotiveNavigation;
    locationManager.pausesLocationUpdatesAutomatically = NO;
    locationManager.allowsBackgroundLocationUpdates = YES;
    locationManager.locationTimeout = 10;
    locationManager.reGeocodeTimeout = 10;

    [locationManager requestLocationWithReGeocode:YES withNetworkState:YES completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) {
        self.adCode = [self CharacterStringMainString:location.rgcData.adCode AddDigit:8 AddString:@"0"];
//         location.rgcData.adCode;
        NSLog(@"%@",location);
        //获取经纬度和该定位点对应的位置信息
    }];
}

- (NSString*)CharacterStringMainString:(NSString*)MainString AddDigit:(int)AddDigit AddString:(NSString*)AddString{
    NSString * ret = [MainString copy];
//    ret = MainString;
    for(int y = 0;y < (AddDigit - MainString.length) ;y++ ){
        ret = [NSString stringWithFormat:@"%@%@",ret,AddString];
    }
    return ret;
}
    
@end
